<?php
/*
<Account Head Controller> 
Author: Naseer Ahmad
Date:   14-07-2011
Last Updated by:
Last Updated on:
*/


class accountHeadsController extends appController
{
	function index()
	{
		
		if(isset($this->data['id'])){
			$info= $this -> accountHeads -> _getRowData("acountHeads", "*", "accountID=".$this->data['id']);
			$this->set("userInfo", $info);
			$this->set("act", "doUpdate");
		}
		
		$this -> set('cmd', $this -> data['cmd']);
		$this -> render('userRegistration');
	}
	
	
	function saveAccount()
	{
		v('Account Name ', $this -> data['accountname']);
		v('Account Type ',  $this -> data['accounttype']);	
		if(!isset($_SESSION['v']))
		{
			
			$res = $this -> accountHeads -> addAccountHeads($this -> data['accountname'],
														$this -> data['accounttype'],	
														$this -> data['firstname'],
														$this -> data['lastname'],
														$this -> data['fulladdress'],
														$this -> data['city'],
														$this -> data['phonenumber'],
														$this -> data['email']);
													
		
				if($res){
					$msg="Account Heads Sucessfully Added!";
					$page="listHeads";
				}
				else{
					$msg="There is some error in inserting record!";
					$page="accountHeads";
				}
		}
		else{
			$page = "accountHeads";
			$msg= $_SESSION['v'];
		}
		
		$red=array('page' => $page,
					'cmd'  => $msg);
		$this -> redirect($red);
	}
	

	function doUpdate()
	{
		
		v('Account Name ', $this -> data['accountname']);
		v('Account Type ',  $this -> data['accounttype']);	
		v('First Name ',  	$this -> data['firstname']);
		v('Last Name ',   $this -> data['lastname']);
		v('Address ',   $this -> data['fulladdress']);
		v('City ',   $this -> data['city']);
		v('Phone ',   $this -> data['phonenumber']);
		v('EMail ',   $this -> data['email'],'email');
						
		if(!isset($_SESSION['v']))
		{
			
			$res = $this -> accountHeads -> updateAccountHeads($this -> data['id'],
														$this -> data['accountname'],
														$this -> data['accounttype'],	
														$this -> data['firstname'],
														$this -> data['lastname'],
														$this -> data['fulladdress'],
														$this -> data['city'],
														$this -> data['phonenumber'],
														$this -> data['email']);
													
		
				if($res){
					$msg="Account Heads Sucessfully Updated!";
					$page="listHeads";
				}
				else{
					$msg="There is some error in inserting record!";
					$page="accountHeads";
				}
		}
		else{
			$page = "accountHeads";
			$msg= $_SESSION['v'];
		}
		
		$red=array('page' => $page,
					'cmd'  => $msg);
		$this -> redirect($red);
	}

	
	
}


?>